<?php

class Application_Model_User extends Application_Model_Abstract{
	protected $_id;
	protected $_username;
	protected $_password;
	protected $_realName;

	/**
	 * Array adapter, zur Vergleich, für DB-Tests
	 * @return array
	 */
	public function toArray() {
		return array('id' => $this->getId(), 'username' => $this->getUsername(), 'password' => $this->getPassword(), 'realName' => $this->getRealName(),);
	}

	/**
	 * @param $userId
	 * @return int
	 */
	public function getBlogCount($userId) {
		$blog = new Application_Model_DbTable_Blog;
		$select = $blog->select();
		$select->from($blog, array('count(*) as amount'))->where("userId = ?", $userId);
		$rows = $blog->fetchRow($select);

		return ($rows['amount']);
	}

	/**
	 * @param int $id
	 * @return Application_Model_User
	 */
	public function setId($id) /* primary Key */ {
		$this->_id = (int) $id;
		return $this;
	}

	/**
	 * @return int
	 */
	public function getId() {
		return $this->_id;

	}

	/**
	 * @param $user
	 * @return Application_Model_User
	 */
	public function setUserName($user) {
		$this->_username = (string) $user;
		return $this;
	}

	/**
	 * @return string
	 */
	public function getUsername() {
		return $this->_username;
	}

	/**
	 * @param string $password
	 * @return Application_Model_User
	 */
	public function setPassword($password) {
		$this->_password = (string) $password;
		return $this;
	}

	/**
	 * @return string
	 */
	public function getPassword() {
		return $this->_password;
	}

	/**
	 * @param $realName
	 * @return Application_Model_User
	 */
	public function setRealName($realName) {
		$this->_realName = (string) $realName;
		return $this;
	}

	/**
	 * @return string
	 */
	public function getRealName() {
		return $this->_realName;
	}

}
